package com.example.gifttalk0.welcome;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;

import android.view.View;
import android.widget.TextView;

import com.example.gifttalk0.MainActivity;
import com.example.gifttalk0.R;

/**
 * Created by Risky57 on 2017/6/27.
 */

public class WelcomeActivity extends Activity {
//定义倒计时时间
    private int count = 5;
    private TextView mTextSkip;
    //倒计时定时器
    private CountDownTimer mTimer;

    @Override
    protected void onCreate ( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        mTextSkip = (TextView) findViewById(R.id.text_skip);
//两个参数，1.定时器总时长，2定时器间隔时间
        mTimer = new CountDownTimer(count * 1000 + 500, 1000) {
            //每隔一个间隔时间都会执行
            @Override
            public void onTick (long millisUntilFinished) {
                mTextSkip.setText(count-- + "秒");
            }
//每次执行在textview显示
            @Override
            public void onFinish () {
                toMainActivity();
            }
        };
        //开启定时器
        mTimer.start();

    }
//显示倒计时的点击事件
    public void onSkip (View view) {
        //取消倒计时，跳转
        mTimer.cancel();
        toMainActivity();
    }

    private void toMainActivity(){
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

}
